package com.dong.designPattern.proxy;

import com.dong.designPattern.proxy.factort.CgLibProxyFactory;
import com.dong.designPattern.proxy.factort.JDKProxyFactory;
import com.dong.designPattern.proxy.targets.UserService;
import com.dong.designPattern.proxy.targets.impl.UserServiceImpl;
import org.junit.Test;

public class ProxyTest {

    @Test
    public void test() {
        // JDK
        UserService userService = new UserServiceImpl();
        userService.getUser();

        System.out.println("=========================================");

        UserService userServiceProxy = (UserService) new JDKProxyFactory(userService).getProxy();
        userServiceProxy.getUser();

        System.out.println(".");
        System.out.println(".");
        System.out.println(".");

        // CgLib
        UserService userServiceProxy2 = (UserService) new CgLibProxyFactory().getProxy(UserServiceImpl.class);
        userServiceProxy2.getUser();
    }
}
